<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet"
	href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/web-register.css">
<script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
<script
	src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>好好花网 - 用户注册</title>
</head>
<body>	
	<div class="content">
		<div class="top"><p>账号注册</p></div>
		<form id="userForm" action="${pageContext.request.contextPath}/user/add"
				method="post">
			<div class="box">
				<span>用户名:&nbsp;&nbsp;</span><input type="text" id="username" name="username"
					placeholder="请使用3-15个中、英文、数字及“-”符号">
			</div>
			<div class="box">
				<span>设置密码:</span><input type="password" id="password" name="password"
					placeholder="6-20个大小写英文字母、符号或数字">
			</div>
			<div class="box">
				<span>确认密码:</span><input type="password" id="password_confirm"
					placeholder="请使用3-15个中、英文、数字及“-”符号">
			</div>
			<div class="box">
				<span>邮&nbsp;&nbsp;&nbsp;箱:&nbsp;&nbsp;&nbsp;</span><input type="text" id="email" name="email"
					placeholder="输入常用邮箱作为验证及找回密码使用">
			</div>
			<div class="box">
				<span>手机号码:</span><input type="text" id="phonenum"  name="phonenum"
					placeholder="输入手机号码">
			</div>
			<input type="hidden" value="1" name="status"/>
			<button type="button" class="btn btn-danger btn-lg" onclick="addUser()">立即注册</button>
		</form>
	</div>
</body>
<script type="text/javascript">
	function addUser() {
		//输入校验
		if($("#username").val() == ""){
			alert("请输入用户名称");
			$("#username").focus();
			return;
		}
		if($("#password").val() == ""){
			alert("请输入用户密码");
			$("#password").focus();
			return;
		}
		if($("#password_confirm").val() == ""){
			alert("请确认用户密码");
			$("#password_confirm").focus();
			return;
		}
		if($("#email").val() == ""){
			alert("请输入用户邮箱");
			$("#email").focus();
			return;
		}
		if($("#phonenum").val() == ""){
			alert("请输入联系电话");
			$("#phonenum").focus();
			return;
		}
		if($("#password").val() != "" && $("#password_confirm").val() != ""){
			if($("#password").val()!= $("#password_confirm").val()){
				alert("两次输入的密码不一致");
				$("#password_confirm").focus();
				return;
			}
		}
		//校验用户名称是否可用
		$.get("${pageContext.request.contextPath}/user/check/username",{"username":$("#username").val()},function(data){
			if(data.status){
				//提交表单
				$("#userForm").submit();
				return;
			}
			alert("用户名称不可用，请重新输入");
			return;
		});
	}
</script>
</html>